﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SzCourt.Logic.BLL;
using Newtonsoft.Json;
using SzCourt.Logic.NBL.DBEntities;

namespace SzCourt.WebSite.manager
{
    public partial class anyouAdd : System.Web.UI.Page
    {
        public string _FirstList = string.Empty;
        public string _SecondList = string.Empty;
        public string _ThirdList = string.Empty;
        public string _FourthList = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!AdminSession.SessionBox.CheckUserSession())
            {
                Response.Redirect("/manager/login.aspx");
            }
            //if (!this.IsPostBack)
            //{
                GetCauseOfActionList();
            //}
        }

        //获取案由类别
        private void GetCauseOfActionList()
        {
            PreCase bll = new PreCase();
            CauseOfActionList result = (CauseOfActionList)bll.GetCauseOfActionList();

            if (result != null)
            {
                this.sltFirstList.DataSource = result.FirstList;
                this.sltFirstList.DataTextField = "CauseOfAction";
                this.sltFirstList.DataValueField = "CauseOfActionID";
                this.sltFirstList.DataBind();

                _FirstList = JavaScriptConvert.SerializeObject(result.FirstList);
                _SecondList = JavaScriptConvert.SerializeObject(result.SecondList);
                _ThirdList = JavaScriptConvert.SerializeObject(result.ThirdList);
                _FourthList = JavaScriptConvert.SerializeObject(result.FourthList);
            }
        }

        private void sss()
        {
            string oneParentId = this.sltFirstList.Value;
            string secParentId = this.sltSecondList.Value;
            string thiParentId = this.sltThirdList.Value;
            string fouParentId = this.sltFourthList.Value;

            string _ID = fouParentId.Length == 0 ? (thiParentId.Length == 0 ? (secParentId.Length == 0 ? oneParentId : secParentId) : thiParentId) : fouParentId;
            int _Level = fouParentId.Length == 0 ? (thiParentId.Length == 0 ? (secParentId.Length == 0 ? 1 : 2) : 3) : 4;

            pCauseOfAction param = new pCauseOfAction();
            param.CauseOfAction = this.txtCauseOfAction.Value;
            param.ParentID = int.Parse(_ID);
            param.Level = _Level;
            PreCase bll = new PreCase();
            bool result = (bool)bll.AddCauseOfAction(param);

            if (result)
            {
                this.divMessage.InnerHtml = "新增案由成功!";
            }
            else
            {
                this.divMessage.InnerHtml = "新增案由失败!";
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            pCauseOfAction param = new pCauseOfAction();
            param.CauseOfAction = this.txtCauseOfAction.Value;
            param.ParentID = int.Parse(this.hdnParentID.Value);
            param.Level = int.Parse(this.hdnLevel.Value);
            PreCase bll = new PreCase();
            bool result = (bool)bll.AddCauseOfAction(param);

            if (result)
            {
                this.divMessage.InnerHtml = "新增案由成功!";
            }
            else
            {
                this.divMessage.InnerHtml = "新增案由失败!";
            }
        }
                
    }
}